
package com.jf.cloud.supplier.controller.supplier;

import com.jf.cloud.api.auth.bo.UserInfoInTokenBO;
import com.jf.cloud.api.supplier.vo.SupplierApiDetailVO;
import com.jf.cloud.common.constant.Constant;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.common.security.AuthUserContext;
import com.jf.cloud.supplier.service.SupplierDetailService;
import com.jf.cloud.supplier.vo.SupplierUserSimpleVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * @author zz
 * @Date 2021/5/12 20:27
 */
@RequestMapping(value = "/s/apply_supplier/supplier_user")
@RestController("supplierSupplierUserController")
@Tag(name = "supplier-供应商用户信息")
public class SupplierUserController {

    @Autowired
    private SupplierDetailService supplierDetailService;

    @GetMapping("/info")
    @Operation(summary = "登录供应商用户信息" , description = "获取当前登录供应商用户的用户信息")
    public ServerResponseEntity<SupplierUserSimpleVO> info() {
        UserInfoInTokenBO userInfoInTokenBO = AuthUserContext.get();
        SupplierUserSimpleVO supplierUserSimple = new SupplierUserSimpleVO();
        supplierUserSimple.setIsAdmin(userInfoInTokenBO.getIsAdmin());
        supplierUserSimple.setIsPassShop(userInfoInTokenBO.getIsPassShop());
        supplierUserSimple.setTenantId(userInfoInTokenBO.getTenantId());
        supplierUserSimple.setUserId(userInfoInTokenBO.getUserId());
        supplierUserSimple.setUserName(userInfoInTokenBO.getUserName());
        if (!Objects.equals(userInfoInTokenBO.getTenantId(), Constant.DEFAULT_SUPPLIER_ID)) {
            SupplierApiDetailVO supplierDetail = supplierDetailService.getBySupplierId(userInfoInTokenBO.getTenantId());
            supplierUserSimple.setAvatar(supplierDetail.getSupplierLogo());
            supplierUserSimple.setSupplierName(supplierDetail.getSupplierName());
        }
        return ServerResponseEntity.success(supplierUserSimple);
    }
}
